package role

import (
	"context"

	"github.com/gogf/gf/v2/errors/gerror"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/role/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/consts"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) UnassignPermission(ctx context.Context, req *v1.UnassignPermissionReq) (res *v1.UnassignPermissionRes, err error) {
	// tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)

	if len(req.PermissionsId) == 0 {
		return nil, gerror.NewCode(consts.MustSelectAtLeastOnePermission)
	}
	in := &v1.UnassignPermissionInput{
		// TenantCode:    tenantCode,
		Id:            req.Id,
		MenuId:        req.MenuId,
		Include:       req.Include,
		PermissionsId: req.PermissionsId,
	}
	out := &v1.UnassignPermissionOutput{}
	out, err = service.Role().UnassignPermission(ctx, in)
	if err != nil {
		return nil, err
	}
	return &v1.UnassignPermissionRes{Rows: out.Rows}, nil
}
